﻿using System;
using System.Collections.Generic;
using System.Data;
using System.Text;
using WebService.DataAccess;using WebService.BusinessEntities;

namespace WebService.DataAccess
{
    /// <summary>
    /// Construct a CasinoUser object from a datareader.
    /// </summary>
    internal class GET_CASINO_USER_PROCFactory : IDomainObjectFactory<CasinoUser>
    {
        public CasinoUser Construct(IDataReader reader)
        {
            CasinoUser casinoUser = new CasinoUser();

            int user_idIndex = reader.GetOrdinal("user_id");
            if (!reader.IsDBNull(user_idIndex))
            {
                casinoUser.user_id = reader.GetInt32(user_idIndex);

            }

            int user_nameIndex = reader.GetOrdinal("user_name");
            if (!reader.IsDBNull(user_nameIndex))
            {
                casinoUser.user_name = reader.GetString(user_nameIndex);

            }

            int user_surnameIndex = reader.GetOrdinal("user_surname");
            if (!reader.IsDBNull(user_surnameIndex))
            {
                casinoUser.user_surname = reader.GetString(user_surnameIndex);

            }

            int nickIndex = reader.GetOrdinal("nick");
            if (!reader.IsDBNull(nickIndex))
            {
                casinoUser.nick = reader.GetString(nickIndex);

            }

            int loginIndex = reader.GetOrdinal("login");
            if (!reader.IsDBNull(loginIndex))
            {
                casinoUser.login = reader.GetString(loginIndex);

            }

            int emailIndex = reader.GetOrdinal("email");
            if (!reader.IsDBNull(emailIndex))
            {
                casinoUser.email = reader.GetString(emailIndex);

            }

            int countryIndex = reader.GetOrdinal("country");
            if (!reader.IsDBNull(countryIndex))
            {
                casinoUser.country = reader.GetString(countryIndex);

            }

            int birth_dateIndex = reader.GetOrdinal("birth_date");
            if (!reader.IsDBNull(birth_dateIndex))
            {
                casinoUser.birth_date = reader.GetDateTime(birth_dateIndex);

            }

            int avatarIndex = reader.GetOrdinal("avatar");
            if (!reader.IsDBNull(avatarIndex))
            {
                casinoUser.avatar = new Byte[(reader.GetBytes(avatarIndex, 0, null, 0, int.MaxValue))];
                reader.GetBytes(avatarIndex, 0, casinoUser.avatar, 0, casinoUser.avatar.Length);

            }

            int creation_dateIndex = reader.GetOrdinal("creation_date");
            if (!reader.IsDBNull(creation_dateIndex))
            {
                casinoUser.creation_date = reader.GetDateTime(creation_dateIndex);

            }

            int is_activeIndex = reader.GetOrdinal("is_active");
            if (!reader.IsDBNull(is_activeIndex))
            {
                casinoUser.is_active = reader.GetBoolean(is_activeIndex);

            }

            int last_logon_dateIndex = reader.GetOrdinal("last_logon_date");
            if (!reader.IsDBNull(last_logon_dateIndex))
            {
                if (!reader.IsDBNull(last_logon_dateIndex))
                {
                    casinoUser.last_logon_date = reader.GetDateTime(last_logon_dateIndex);
                }

            }

            int last_logout_dateIndex = reader.GetOrdinal("last_logout_date");
            if (!reader.IsDBNull(last_logout_dateIndex))
            {
                if (!reader.IsDBNull(last_logout_dateIndex))
                {
                    casinoUser.last_logout_date = reader.GetDateTime(last_logout_dateIndex);
                }

            }

            int last_update_dateIndex = reader.GetOrdinal("last_update_date");
            if (!reader.IsDBNull(last_update_dateIndex))
            {
                casinoUser.last_update_date = reader.GetDateTime(last_update_dateIndex);

            }


            return casinoUser;
        }
    }
}

